package com.dal.db.bean;

import static com.dal.db.StaticResource.ChannelAppResource.*;
import com.sojoys.artifact.factory.bytebuff.IByteBuff;
import org.apache.commons.lang3.ArrayUtils;
import com.sojoys.artifact.build.data.base.BasePojo;
import java.util.List;
import java.sql.SQLException;
import com.sojoys.artifact.tools.ToolMap;
import com.sojoys.artifact.tools.SK_Plus;
import com.sojoys.artifact.tools.ToolCopy;
import java.sql.ResultSet;
import java.util.Map;
import com.dal.db.cache.ChannelCache;
import com.alibaba.fastjson.JSONObject;
import com.dal.db.cache.ChannelAppCache;
import com.dal.db.cache.AccountCache;
import com.sojoys.artifact.constant.DataModelKeyEnum;
import static com.dal.db.StaticResource.ChannelAppResource.*;
/**
 * 渠道包
 */
public class ChannelApp extends BasePojo<ChannelApp> {
	
	
	/**
	 * 索引值
	 */
	private String[] indexValues = new String[3];
	
	/**
	* id
	*/
	private int id;
	
	/**
	* 渠道包名称
	*/
	private String name;
	
	/**
	* 包ID
	*/
	private String appKey;
	
	/**
	* 渠道ID
	*/
	private int channelId;
	
	/**
	* 最大客户端版本号
	*/
	private String maxClientVer;
	
	/**
	* 最小客户端版本号
	*/
	private String minClientVer;
	
	/**
	* 是否需要激活码
	*/
	private boolean needActivateCode;
	
	/**
	* 是否需要密码
	*/
	private boolean needPassword;
	
	/**
	* 开服时间
	*/
	private java.util.Date openServerDate;
	
	/**
	* create_date
	*/
	private java.util.Date createDate;
	
	/**
	* modified_date
	*/
	private java.util.Date modifiedDate;
	
	
	@Deprecated
	public static ChannelApp builder() {
		ChannelApp channelApp = new ChannelApp();
		return channelApp;
	}
	
	@Deprecated
	public ChannelApp() {
		super();
	}
	
	public ChannelApp(int id, String name, String appKey, int channelId, String maxClientVer, String minClientVer, boolean needActivateCode, boolean needPassword, java.util.Date openServerDate) {
		super();
		this.id = id;
		this.name = name;
		this.appKey = appKey;
		this.channelId = channelId;
		this.maxClientVer = maxClientVer;
		this.minClientVer = minClientVer;
		this.needActivateCode = needActivateCode;
		this.needPassword = needPassword;
		this.openServerDate = openServerDate;
		this.createDate = new java.util.Date();
		this.modifiedDate = new java.util.Date();
	}
	
	/**
	 * id
	 */
	public int getId() {return id;}
	
	/**
	 * id
	 */
	public ChannelApp setId(int id) {this.id = id;return this;}
	
	/**
	 * 渠道包名称
	 */
	public String getName() {return name;}
	
	/**
	 * 渠道包名称
	 */
	public ChannelApp setName(String name) {this.name = name;return this;}
	
	/**
	 * 包ID
	 */
	public String getAppKey() {return appKey;}
	
	/**
	 * 包ID
	 */
	public ChannelApp setAppKey(String appKey) {this.appKey = appKey;return this;}
	
	/**
	 * 渠道ID
	 */
	public int getChannelId() {return channelId;}
	
	/**
	 * 渠道ID
	 */
	public ChannelApp setChannelId(int channelId) {this.channelId = channelId;return this;}
	
	/**
	 * 最大客户端版本号
	 */
	public String getMaxClientVer() {return maxClientVer;}
	
	/**
	 * 最大客户端版本号
	 */
	public ChannelApp setMaxClientVer(String maxClientVer) {this.maxClientVer = maxClientVer;return this;}
	
	/**
	 * 最小客户端版本号
	 */
	public String getMinClientVer() {return minClientVer;}
	
	/**
	 * 最小客户端版本号
	 */
	public ChannelApp setMinClientVer(String minClientVer) {this.minClientVer = minClientVer;return this;}
	
	/**
	 * 是否需要激活码
	 */
	public boolean isNeedActivateCode() {return needActivateCode;}
	
	/**
	 * 是否需要激活码
	 */
	public ChannelApp setNeedActivateCode(boolean needActivateCode) {this.needActivateCode = needActivateCode;return this;}
	
	/**
	 * 是否需要密码
	 */
	public boolean isNeedPassword() {return needPassword;}
	
	/**
	 * 是否需要密码
	 */
	public ChannelApp setNeedPassword(boolean needPassword) {this.needPassword = needPassword;return this;}
	
	/**
	 * 开服时间
	 */
	public java.util.Date getOpenServerDate() {return openServerDate;}
	
	/**
	 * 开服时间
	 */
	public ChannelApp setOpenServerDate(java.util.Date openServerDate) {this.openServerDate = openServerDate;return this;}
	
	/**
	 * create_date
	 */
	public java.util.Date getCreateDate() {return createDate;}
	
	/**
	 * create_date
	 */
	protected ChannelApp setCreateDate(java.util.Date createDate) {this.createDate = createDate;return this;}
	
	/**
	 * modified_date
	 */
	public java.util.Date getModifiedDate() {return modifiedDate;}
	
	/**
	 * modified_date
	 */
	protected ChannelApp setModifiedDate(java.util.Date modifiedDate) {this.modifiedDate = modifiedDate;return this;}
	
	
	// 代理
	
	protected Object[] getColumnNames(DataModelKeyEnum e){
		switch (e) {
		case SOURCE:
			return SOURCE_COLUMN_NAMES;
		case PINGYING:
			return PINGYING_COLUMN_NAMES;
		case HASHCODE:
			return HASHCODE_COLUMN_NAMES;
		case REMARKS:
			return SOURCE_COLUMN_REMARKS;
		default:
			return PINGYING_COLUMN_NAMES;
		}
	}
	
	protected Object[] getFKTableNames(DataModelKeyEnum e){
		switch (e) {
		case SOURCE:
			return FK_SOURCE_TABLE_NAMES;
		case PINGYING:
			return FK_PINGYING_TABLE_NAMES;
		case HASHCODE:
			return FK_HASHCODE_TABLE_NAMES;
		default:
			return FK_PINGYING_TABLE_NAMES;
		}
	}
	
	protected Object[] getFKColumnNames(DataModelKeyEnum e){
		switch (e) {
		case SOURCE:
			return FK_SOURCE_COLUMN_NAMES;
		case PINGYING:
			return FK_PINGYING_COLUMN_NAMES;
		case HASHCODE:
			return FK_HASHCODE_COLUMN_NAMES;
		default:
			return FK_PINGYING_TABLE_NAMES;
		}
	}
	
	protected String[] getBasicTypes(){
		return COLUMN_BASICTYPES;
	}
	
	protected Class[] getClassTypes(){
		return COLUMN_CLASSTYPES;
	}
	
	protected String[] getColumnTypes(){
		return COLUMN_COLUMNTYPES;
	}
	
	protected int getColumnCount(){
		return COLUMN_COUNT;
	}
	
	protected Object[] getColumeValues(){
		Object[] values = new Object[COLUMN_COUNT];
        values[0] = this.id;
        values[1] = this.name;
        values[2] = this.appKey;
        values[3] = this.channelId;
        values[4] = this.maxClientVer;
        values[5] = this.minClientVer;
        values[6] = this.needActivateCode;
        values[7] = this.needPassword;
        values[8] = this.openServerDate;
        values[9] = this.createDate;
        values[10] = this.modifiedDate;
        return values;
	}
	
	public ChannelApp deepCopy(){
		ChannelApp channelApp = null;
		try {
			channelApp = (ChannelApp) super.clone();
		    channelApp.setOpenServerDate(ToolCopy.copyObject(this.openServerDate));
		    channelApp.setCreateDate(ToolCopy.copyObject(this.createDate));
		    channelApp.setModifiedDate(ToolCopy.copyObject(this.modifiedDate));
		    // 克隆索引
		    channelApp.indexValues = ArrayUtils.clone(indexValues);
			return channelApp;
		} catch (CloneNotSupportedException e) {
			e.printStackTrace();
		}
		return channelApp;
	}
	
	
	protected Map<Object, Object> toMap(Object[] keys,Map<Object, Object> map){
        map.put(keys[0], this.id);
        map.put(keys[1], this.name);
        map.put(keys[2], this.appKey);
        map.put(keys[3], this.channelId);
        map.put(keys[4], this.maxClientVer);
        map.put(keys[5], this.minClientVer);
        map.put(keys[6], this.needActivateCode);
        map.put(keys[7], this.needPassword);
        map.put(keys[8], this.openServerDate);
        map.put(keys[9], this.createDate);
        map.put(keys[10], this.modifiedDate);
        return map;
    }
    
    protected ChannelApp createForMap(Object[] keys,Map map){
   		this.id = (int)map.get(keys[0]);
   		this.name = (String)map.get(keys[1]);
   		this.appKey = (String)map.get(keys[2]);
   		this.channelId = (int)map.get(keys[3]);
   		this.maxClientVer = (String)map.get(keys[4]);
   		this.minClientVer = (String)map.get(keys[5]);
   		this.needActivateCode = (boolean)map.get(keys[6]);
   		this.needPassword = (boolean)map.get(keys[7]);
   		this.openServerDate = (java.util.Date)map.get(keys[8]);
   		this.createDate = (java.util.Date)map.get(keys[9]);
   		this.modifiedDate = (java.util.Date)map.get(keys[10]);
        return this;
    }
	
	
	protected JSONObject toJSONObject(Object[] keys,JSONObject obj){
        obj.put(keys[0], this.id);
        obj.put(keys[1], this.name);
        obj.put(keys[2], this.appKey);
        obj.put(keys[3], this.channelId);
        obj.put(keys[4], this.maxClientVer);
        obj.put(keys[5], this.minClientVer);
        obj.put(keys[6], this.needActivateCode);
        obj.put(keys[7], this.needPassword);
        obj.put(keys[8], this.openServerDate);
        obj.put(keys[9], this.createDate);
        obj.put(keys[10], this.modifiedDate);
        return obj;
    }
    
    protected ChannelApp createForJSONObject(Object[] keys,JSONObject obj){
	    this.id = obj.getIntValue(keys[0]);
	    this.name = obj.getString(keys[1]);
	    this.appKey = obj.getString(keys[2]);
	    this.channelId = obj.getIntValue(keys[3]);
	    this.maxClientVer = obj.getString(keys[4]);
	    this.minClientVer = obj.getString(keys[5]);
	    this.needActivateCode = obj.getBooleanValue(keys[6]);
	    this.needPassword = obj.getBooleanValue(keys[7]);
	    this.openServerDate = obj.getDate(keys[8]);
	    this.createDate = obj.getDate(keys[9]);
	    this.modifiedDate = obj.getDate(keys[10]);
        return this;
    }
    
    
    public ChannelApp createForResultSet(ResultSet rs) throws SQLException{
	    this.id = rs.getInt(SOURCE_COLUMN_NAMES[0]);
	    this.name = rs.getString(SOURCE_COLUMN_NAMES[1]);
	    this.appKey = rs.getString(SOURCE_COLUMN_NAMES[2]);
	    this.channelId = rs.getInt(SOURCE_COLUMN_NAMES[3]);
	    this.maxClientVer = rs.getString(SOURCE_COLUMN_NAMES[4]);
	    this.minClientVer = rs.getString(SOURCE_COLUMN_NAMES[5]);
	    this.needActivateCode = rs.getBoolean(SOURCE_COLUMN_NAMES[6]);
	    this.needPassword = rs.getBoolean(SOURCE_COLUMN_NAMES[7]);
	    this.openServerDate = rs.getTimestamp(SOURCE_COLUMN_NAMES[8]);
	    this.createDate = rs.getTimestamp(SOURCE_COLUMN_NAMES[9]);
	    this.modifiedDate = rs.getTimestamp(SOURCE_COLUMN_NAMES[10]);
	    return this;
    }
    
    protected void writeBytes(IByteBuff byteBuf){
	    byteBuf.writeInt(this.id);
	    byteBuf.writeString(this.name);
	    byteBuf.writeString(this.appKey);
	    byteBuf.writeInt(this.channelId);
	    byteBuf.writeString(this.maxClientVer);
	    byteBuf.writeString(this.minClientVer);
	    byteBuf.writeBoolean(this.needActivateCode);
	    byteBuf.writeBoolean(this.needPassword);
	    byteBuf.writeDate(this.openServerDate);
	    byteBuf.writeDate(this.createDate);
	    byteBuf.writeDate(this.modifiedDate);
    }
	
	protected ChannelApp readBytes(IByteBuff byteBuf){
	    this.id = byteBuf.readInt(null);
	    this.name = byteBuf.readString(null);
	    this.appKey = byteBuf.readString(null);
	    this.channelId = byteBuf.readInt(null);
	    this.maxClientVer = byteBuf.readString(null);
	    this.minClientVer = byteBuf.readString(null);
	    this.needActivateCode = byteBuf.readBoolean(null);
	    this.needPassword = byteBuf.readBoolean(null);
	    this.openServerDate = byteBuf.readDate(null);
	    this.createDate = byteBuf.readDate(null);
	    this.modifiedDate = byteBuf.readDate(null);
	    return this;
	}
    
    
    protected JSONObject exportFKTableMap(Object[] keys,JSONObject map,DataModelKeyEnum e){
		// account
		map.put(keys[0],exprotHelp(this.getAccountsFkChannelAppId(),e));
        return map;
    }
    
    protected boolean importFKTableMap(Object[] keys,JSONObject map,DataModelKeyEnum e){
		// account
		improtHelp(map.getJSONArray(keys[0]),Account.builder(),e,0,this.getId());
		return true;
    }
    
	/** 取得[account] */
	public List<Account> getAccountsFkChannelAppId(){
		return AccountCache.me().getByChannelAppId(id);
	}
	
	/** 取得[channel]*/
	public Channel getChannelPkChannelId(){
		return ChannelCache.me().getById(channelId);
	}
	
    /** 级联删除(延迟入库) */
    public boolean deleteAndSon(){
    	return false;
    }
    
    /** 级联删除(及时入库) */
    public boolean deleteAndSonAndFlush(){
    	return false;
    }
    
    /** 延迟插入数据库 */
    public ChannelApp insert(){
    	return ChannelAppCache.me().insert(this);
    }
    /** 延迟更新数据库 */
    public ChannelApp update(){
    	return ChannelAppCache.me().update(this);
    }
    /** 延迟删除数据库 */
    public boolean delete(){
    	return ChannelAppCache.me().delete(this);
    }
    /** 即时插入数据库 */
    public ChannelApp insertAndFlush(){
    	return ChannelAppCache.me().insertAndFlush(this);
    }
    /** 即时更新数据库 */
    public ChannelApp updateAndFlush(){
    	return ChannelAppCache.me().updateAndFlush(this);
    }
    /** 即时删除数据库 */
    public boolean deleteAndFlush(){
    	return ChannelAppCache.me().deleteAndFlush(this);
    }
    
    
	
	/**
	 * 同步索引值
	 */
	public ChannelApp syncIndexValues(){
		indexValues[0] = SK_Plus.b(getId()).e();
		indexValues[1] = SK_Plus.b(getChannelId(),"_",getAppKey()).e();
		indexValues[2] = SK_Plus.b(getChannelId()).e();
		return this;
	}
	/**
	 * 取得索引
	 */
	public String[] getIndexValues(){
		return indexValues;
	}
	
	protected Object getPrimaryKey(){
		return getId();
	}
	
	protected void setPrimaryKey(Object key){
		setId((int)key);
	}
//自定义内容起始位置
//自定义内容结束位置
}